package com.example.administrator.yunniuusedcar.mineModular;

import android.content.Intent;
import android.widget.TextView;

import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.yunniuusedcar.R;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;

public class ScanQRCodeActivity extends BaseActivity {


    private final int REQUEST_CODE_SCAN = 111;
    private TextView result;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_scan_qrcode;
    }

    @Override
    public void initView() {
        initScan();
        result = findViewById(R.id.resultTv);
    }

    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
    }

    private void initScan() {
        ZxingConfig config = new ZxingConfig();
        config.setShowbottomLayout(true);    // 底部布局（闪光灯、相册）
        config.setShake(true);     // 震动
        config.setShowAlbum(true);  //相册
        config.setShowFlashLight(true);  //灯

        Intent intent = new Intent(this, CaptureActivity.class);
        startActivityForResult(intent, REQUEST_CODE_SCAN);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // // 扫描二维码/条码回传
        if (requestCode == REQUEST_CODE_SCAN && resultCode == RESULT_OK) {
            if (data != null) {
                String content = data.getStringExtra(Constant.CODED_CONTENT);
                result.setText("Scanning result：" + content);
            }
        }
    }
}